<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" > 

<html>
<head>
<base href="<%=basePath%>">
<title>症状列表</title>
<link rel="stylesheet" type="text/css" href="./js/bootstrap-3.3.5-dist/css/bootstrap.css" />
<link href="./js/metisMenu/metisMenu.min.css" rel="stylesheet">
<link href="./css/sb-admin/sb-admin-2.css" rel="stylesheet">
<link rel="stylesheet" href="./js/font-awesome/css/font-awesome.min.css">
<link href="./css/base.css" rel="stylesheet">
<link rel="stylesheet" href="./js/bootstrap-table/bootstrap-table.min.css">
<link rel="stylesheet" href="./js/bootstrap-multiselect/bootstrap-multiselect.css"/>
<link rel="stylesheet" href="./js/bootstrap-3.3.5-dist/css/bootstrap-datetimepicker.css">
<link rel="stylesheet" href="./css/illness.css">
<script type="text/javascript" src="./js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="./js/bootstrap-3.3.5-dist/js/bootstrap.js"></script>
<script src="./js/bootstrap-table/bootstrap-table-all.js"></script>
<script src="./js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript" src="./js/metisMenu/metisMenu.js"></script>
<script src="./js/bootstrap-multiselect/bootstrap-multiselect.js"></script>
<script src="./js/bootstrap-3.3.5-dist/js/bootstrap-datetimepicker.js"></script>
<script src="./js/bootstrap-3.3.5-dist/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="./js/bootstrap-jquery-plugin/jquery.bootstrap.js"></script>
<script type="text/javascript" src="./js/common.js"></script>
<script type="text/javascript" src="./js/xss.js"></script>
</head>
<body>
<jsp:include page="../template/head.jsp" />
<jsp:include page="../template/leftnav.jsp" />
<div id="page-wrapper">
	<div>
		<h1>症状列表</h1>
	</div>
	<div class="content">
		<form class="form-inline">
			<div class="form-group">
				<label for="ssymptom">症状名称：</label>
				<input type="text" id="ssymptom" class="form-control" placeholder="请输入症状名称" onkeyup="filters(this)" onchange="filters(this)">
			</div>
			<div class="form-group">
				<button class="btn  search-btn" id="search">搜索</button>
				<button id="reset" class="btn btn-default">重置</button>
			</div>
		</form>

		 <table id="table" data-toolbar="#toolbar" data-toggle="table" data-row-style="rowStyle" data-classes="table  table-no-bordered"
	           data-minimum-count-columns="2"  data-cache="false" data-pagination="true"  data-striped="data-striped"
	           data-page-list="[5, 10, 20, 30]"  data-query-params="tableQueryParams" style="word-break:break-all;"
	           data-side-pagination="server" data-page-size=10 data-url="./adminIllness/getSymptomList"
	           data-detail-view="true"
			   data-detail-formatter="detailFormatter">
	           <thead>
				<tr class="headTr">
					<th data-field="symptom" data-width="30%" >症状名称</th>
					<th data-field="adminCode" data-width ="20%">设置人</th>
					<th data-field="createdTime" data-width ="20%" data-formatter="dateStatusFormatter">状态</th>
					<th data-field="createdTime" data-width ="20%" data-formatter="dateFormatter">设置日期</th>
					<th data-field="operation" data-width ="10%" data-formatter="operFormatter">操作</th>
				</tr>
			</thead>
	    </table>
	    <div id="illOperTemp" style="display:none">
			<ul class="list-inline">
				<li role="presentation"><a role="button" class="btn btn-primary" style="display: none">是常见</a></li>
				<li role="presentation"><a role="button" class="btn btn-danger" style="display: none">非常见</a></li>
			</ul>
		</div>
    </div>
</div>
<script>

$(function () {
	
	"use strict";
	
	$('#search').on('click', function (e) {
		e.preventDefault();
		searchOrder();
	});
	
});

function tableQueryParams(params) {
	var queryObj = getQueryObject();
	var newParams = $.extend(params,queryObj);
	return newParams;
}
	
function getQueryObject(){
	var queryObj;
	var symptom = $("#ssymptom").val();
	
	var queryObj = {

		symptom: symptom,
	}
	
	if(symptom ==""){
		delete queryObj.symptom;
	}
	
	return queryObj;
}
	
function searchOrder(){
	var queryObj = getQueryObject();
	$('#table').bootstrapTable('refresh', {
		query : {
			offset: 0
		},
		url : "./adminIllness/getSymptomList",
		silent : true
	});
}


function operFormatter(value, row) {
	var operTemp = $("#illOperTemp").clone();
	var lis = operTemp.find("ul li");
	if(row.createdTime!=null){
		lis.eq(1).find("a").show();
		lis.eq(1).find("a").attr("onClick", "setSymptomCommonNot(\""+row.symptom+"\")");
	}else{
		lis.eq(0).find("a").show();
		lis.eq(0).find("a").attr("onClick", "setSymptomCommon(\""+row.symptom+"\")");
	}
	return operTemp.html();
}

function setSymptomCommon(symptom){
	$.ajax({
		url : "./adminIllness/setSymptomCommon",
		type : 'POST',
		data : {
			symptom :symptom
		},
		dataType : 'json',
		success : function(ret) {
                if(ret.resultCode == 0){
                    $.messager.popup("操作成功");
                    $('#table').bootstrapTable('refresh', {
/* 					query : {
						offset: 0
					}, */
					silent : true
				});
                }else{
                    $.messager.popup("操作失败");
                }
		}
	});
}

function setSymptomCommonNot(symptom){
	$.ajax({
		url : "./adminIllness/setSymptomCommonNot",
		type : 'POST',
		data : {
			symptom :symptom
		},
		dataType : 'json',
		success : function(ret) {
                if(ret.resultCode == 0){
                    $.messager.popup("操作成功");
                    $('#table').bootstrapTable('refresh', {
/* 					query : {
						offset: 0
					}, */
					silent : true
				});
                }else{
                    $.messager.popup("操作失败");
                }
		}
	});	
}

function dateFormatter(value, row){
	if(value!=null && value!=''){
		return getSmpFormatDateByLong(value, true);
	}else{
		return '-';
	}
}

function dateStatusFormatter(value, row){
	if(value!=null && value!=''){
		return "常见";
	}else{
		return '-';
	}
}

function illNamesFormatter(row){
	var partArr = [];
	for(var i=0;i<row.illNames.length;i++){
		if(row.illNames[i]=='' || row.illNames[i]==null){
			continue;
		}
		partArr.push(row.illNames[i]);
	}
	
	return unique(partArr).join("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
}

function historySortsFormatter(row){
	var partArr = [];
	for(var i=0;i<row.historySorts.length;i++){
		if(row.historySorts[i]=='' || row.historySorts[i]==null){
			continue;
		}
		partArr.push(row.historySorts[i]);
	}
	
	return unique(partArr).join("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
}

function detailFormatter(index, row) {
	var html=[];
	html.push('<div style="padding:10;">');
	html.push('<div class="bs-callout bs-callout-info">');
	
	for(var i=0;i<row.details.length;i++){
		html.push('<p><b>疾病名称:</b></br>' + row.details[i].illName + '</p>');
		html.push('<p><b>录入人名:</b></br>' + row.details[i].adminName + '</p>');
		var str = '';
		for(var j=0;j<row.details[i].historySorts.length;j++){
			str = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + row.details[i].historySorts[j];
		}
		html.push('<p><b>相关分类:</b></br>' + (str==''?'无':str) + '</p>');
		html.push('<p style="border:1px solid #efefef"></p>');
	}
	
	html.push('</div>');
	html.push('</div>');
	return html.join('');
}
</script>
</body>
</html>